package com.lx.demo1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyInvocationHandler implements InvocationHandler {

    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }

    //生成代理实例
    public Object getProxyExample() {
        return Proxy.newProxyInstance(this.getClass().getClassLoader(), this.target.getClass().getInterfaces(), this);
    }

    //处理代理实例，返回处理结果
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object o =  method.invoke(this.target, args);
        lookHouse();
        signContract();
        return o;
    }

    public void lookHouse(){
        System.out.println("中介带你看房！");
    }

    public void signContract(){
        System.out.println("签订租赁合同！");
    }
}
